<template>
    <section class="indexConfirm">
        <div style="min-height: 400px">
            <div class="title">
              <div class="checked">已审核数量：<span>{{finishList.length - unFinisList.length}}</span></div>
              <div class="noCheck">未审核数量：<span>{{unFinisList.length}}</span></div>
            </div>
            <div v-for="item in finishList" :class="item.status=='2' || item.status=='3'?'finishDiv':'unFinishDiv'" v-if="finishList.length>0">
                <label class="self-define" v-if="item.status=='2' || item.status=='3'">
                    <i class="el-icon-upload-success el-icon-check"></i>
                </label>
                <div>
                    {{item.objectName}}
                </div>
            </div>
            <div v-if="finishList.length==0" class="noData" >
                暂无
            </div>
            <div class="confirm_input" v-if="!showButton">
              <div>
                <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="确认人" prop="name">
                        <el-input v-model="form.name"  placeholder="请输入确认人姓名"></el-input>
                    </el-form-item>
                </el-form>
              </div>
              <div class="confirmBtn">
                  <el-button type="primary" size="large" @click="confirmIndex('form')">确认</el-button>
              </div>
            </div>
        </div>

    </section>
</template>

<script>
    export default {
        name: "IndexConfirm",
        props:{
            task:{
                type:Object
            }
        },
        data(){
            return{
                finishList: [],
                unFinisList: [],
                form: {},
                rules: {
                    name: [
                        { required: true, message: '请输入确认人姓名', trigger: 'blur' },
                    ],
                },
                showButton: Boolean
            }
        },
        watch: {
            'task.id': {
                handler: function () {
                    this.showFinishList();
                }
            }
        },
        methods:{
            showFinishList(){
                this.finishList = [];
                this.unFinisList = [];
                this.$http('POST',`/identity/cadreTaskObject/list`, {taskId: this.task.id},false).then(data=>{
                    this.finishList = data;
                    data.forEach(item => {
                      if (item.status == '0' || item.status =='1') {
                        this.unFinisList.push(item);
                      }
                    });
                    this.isShowButton();
                });
            },
            confirmIndex(form){
                if(this.unFinisList.length==0){
                    this.$refs.form.validate((valid) => {
                        if (valid) {
                          this.$http('GET', `/identity/cadreTaskObject/quota/confirm?taskId=${this.task.id}`,  false).then(() => {
                            this.$message({
                              type: 'success',
                              message: '确认成功'
                            })
                          })
                        this.showFinishList();
                        this.isShowButton();
                        } else {
                            return false;
                        }
                    });
                }else{
                    this.$message({
                        type:'warning',
                        message:'指标还未全部制定完成，无法确认！'
                    })
                }

            },
            isShowButton () {
              this.showButton = this.finishList.every((item) => {
                return item.status === '3'
              })
            }
        },
        mounted() {
            this.showFinishList();
            
                console.log(this.task);
                
        }
    }
</script>

<style scoped>
    .title {
      margin: 15px 0 0 20px;
    }
    .checked, .noCheck {
        height: 30px;
        line-height: 30px;
        font-size: 20px;
        font-weight: 700;
    }
    .checked span{
      color: #2da04b;
    }
    .noCheck span{
      color: crimson;
    }
    .indexConfirm{
        text-align: left;
    }
    .indexConfirm .finishDiv{
        width: 190px;
        height: 100px;
        display: inline-block;
        margin: 20px;
        text-align: center;
        line-height: 50px;
        background: linear-gradient(30deg, #48bb94, #2da04b);
        box-shadow: 0 12px 20px -10px rgba(76, 175, 80, .28), 0 4px 20px 0 rgba(0, 0, 0, .12), 0 7px 8px -5px rgba(76, 175, 80, .2);
        color:white;
        font-weight: bold;
        border-radius: 5px;
    }
    .indexConfirm .unFinishDiv{
        width: 190px;
        height: 100px;
        display: inline-block;
        margin: 20px;
        text-align: center;
        line-height: 100px;
        background: white;
        box-shadow: 0 12px 20px -10px rgba(76, 175, 80, .28), 0 4px 20px 0 rgba(0, 0, 0, .12), 0 7px 8px -5px rgba(76, 175, 80, .2);
        color:grey;
        font-weight: bold;
        border-radius: 5px;
    }
    .indexConfirm .finishDiv .self-define {
        position: relative;
        left: 160px;
        top: -6px;
        width: 40px;
        height: 24px;
        background: transparent;
        text-align: center;
        -webkit-transform: rotate(45deg);
        transform: rotate(45deg);
        display: none;
    }
    .indexConfirm .finishDiv .self-define i {
        color: white;
        transform: rotate(-45deg);
       /* top: 9px;
        left: 0;*/
        font-size: 20px;
        font-weight: bold;
        position: relative;
    }
    .indexConfirm .finishDiv:hover .self-define, .indexConfirm .finishDiv .self-define{
        display: block;
    }
    .confirm_input {
      position: relative;
    }
    .indexConfirm .confirmBtn{
        right: 50px;
        bottom: 0px;
        position: absolute;
    }
    .indexConfirm .noData{
        width: 100%;
        height: 200px;
        margin-top:100px;
        text-align: center;
    }
</style>
